class ProcessInstancesController < ApplicationController
  before_action :set_process_instance, only: [:show, :edit, :update, :destroy]

  # GET /process_instances
  # GET /process_instances.json
  def index
    @process_instances = ProcessInstance.all
  end

  # GET /process_instances/1
  # GET /process_instances/1.json
  def show
  end

  # GET /process_instances/new
  def new
    @process_instance = ProcessInstance.new
  end

  # GET /process_instances/1/edit
  def edit
  end

  # POST /process_instances
  # POST /process_instances.json
  def create
    @process_instance = ProcessInstance.new(process_instance_params)

    respond_to do |format|
      if @process_instance.save
        format.html { redirect_to @process_instance, notice: 'Process instance was successfully created.' }
        format.json { render :show, status: :created, location: @process_instance }
      else
        format.html { render :new }
        format.json { render json: @process_instance.errors, status: :unprocessable_entity }
      end
    end
  end

  # PATCH/PUT /process_instances/1
  # PATCH/PUT /process_instances/1.json
  def update
    respond_to do |format|
      if @process_instance.update(process_instance_params)
        format.html { redirect_to @process_instance, notice: 'Process instance was successfully updated.' }
        format.json { render :show, status: :ok, location: @process_instance }
      else
        format.html { render :edit }
        format.json { render json: @process_instance.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /process_instances/1
  # DELETE /process_instances/1.json
  def destroy
    @process_instance.destroy
    respond_to do |format|
      format.html { redirect_to process_instances_url, notice: 'Process instance was successfully destroyed.' }
      format.json { head :no_content }
    end
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_process_instance
      @process_instance = ProcessInstance.find(params[:id])
    end

    # Never trust parameters from the scary internet, only allow the white list through.
    def process_instance_params
      params.require(:process_instance).permit(:process_define_id, :creator_id, :start_at, :end_at, :status, :business_key)
    end
end
